package com.vv.tools.modules.auth.handler;

import com.vv.tools.common.message.Result;
import com.vv.tools.common.message.ResultEnum;
import com.vv.tools.common.util.ResponseUtil;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

/**
 * @author wen.li
 * 用户未登录
 * 用于处理用户尝试访问受保护资源但未进行身份验证的情况。
 */
@Component("loginAuthenticationHandler")
public class LoginAuthenticationHandler implements AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) {
        ResponseUtil.of(response, Result.fail(ResultEnum.AUTH_LOGIN_AUTHENTICATION));
    }
}
